package com.deyang.mycommon.ui.activity.study;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.deyang.mycommon.R;
import com.deyang.mycommon.ui.baseui.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EditTextActivity extends BaseActivity implements View.OnTouchListener {


    @BindView(R.id.et1)
    EditText et1;
    @BindView(R.id.et2)
    EditText et2;
    @BindView(R.id.et3)
    EditText et3;
    @BindView(R.id.et4)
    EditText et4;

    @BindView(R.id.btn)
    Button btn;

    private EditSelect editSelect;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_edit_text);
        ButterKnife.bind(this);

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        editSelect = EditSelect.Et1;

        et1.setOnTouchListener(this);
        et2.setOnTouchListener(this);
        et3.setOnTouchListener(this);
        et4.setOnTouchListener(this);

        et1.setText("111");
        et2.setText("222");
        et3.setText("333");
        et4.setText("444");
    }

    @OnClick({
            R.id.btn,
    })
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

            case R.id.btn:
                if (editSelect == EditSelect.Et1) {
                    showToastInfo("1");
                } else if (editSelect == EditSelect.Et2) {
                    showToastInfo("2");
                } else if (editSelect == EditSelect.Et3) {
                    showToastInfo("3");
                } else if (editSelect == EditSelect.Et4) {
                    showToastInfo("4");
                }
                break;
        }
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (v.getId()) {
            case R.id.et1:
                editSelect = EditSelect.Et1;
                break;
            case R.id.et2:
                editSelect = EditSelect.Et2;
                break;
            case R.id.et3:
                editSelect = EditSelect.Et3;
                break;
            case R.id.et4:
                editSelect = EditSelect.Et4;
                break;
        }
        return false;
    }
}

enum EditSelect {
    Et1,
    Et2,
    Et3,
    Et4,
}
